package com.sdb.medicalrecord.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sdb.common.annotation.Log;
import com.sdb.common.core.controller.BaseController;
import com.sdb.common.core.domain.AjaxResult;
import com.sdb.common.enums.BusinessType;
import com.sdb.medicalrecord.domain.TdMedicalrecord;
import com.sdb.medicalrecord.service.ITdMedicalrecordService;
import com.sdb.common.utils.poi.ExcelUtil;
import com.sdb.common.core.page.TableDataInfo;

/**
 * 病历Controller
 * 
 * @author yyh
 * @date 2025-01-24
 */
@RestController
@RequestMapping("/medicalrecord/medicalrecord")
public class TdMedicalrecordController extends BaseController
{
    @Autowired
    private ITdMedicalrecordService tdMedicalrecordService;

    /**
     * 查询病历列表
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @GetMapping("/list")
    public TableDataInfo list(TdMedicalrecord tdMedicalrecord)
    {
        startPage();
        List<TdMedicalrecord> list = tdMedicalrecordService.selectTdMedicalrecordList(tdMedicalrecord);
        return getDataTable(list);
    }

    /**
     * 导出病历列表
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "病历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TdMedicalrecord tdMedicalrecord)
    {
        List<TdMedicalrecord> list = tdMedicalrecordService.selectTdMedicalrecordList(tdMedicalrecord);
        ExcelUtil<TdMedicalrecord> util = new ExcelUtil<TdMedicalrecord>(TdMedicalrecord.class);
        util.exportExcel(response, list, "病历数据");
    }

    /**
     * 获取病历详细信息
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @GetMapping(value = "/{clinicId}")
    public AjaxResult getInfo(@PathVariable("clinicId") String clinicId)
    {
        return success(tdMedicalrecordService.selectTdMedicalrecordByClinicId(clinicId));
    }

    /**
     * 新增病历
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "病历", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TdMedicalrecord tdMedicalrecord)
    {
        return toAjax(tdMedicalrecordService.insertTdMedicalrecord(tdMedicalrecord));
    }

    /**
     * 修改病历
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "病历", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TdMedicalrecord tdMedicalrecord)
    {
        return toAjax(tdMedicalrecordService.updateTdMedicalrecord(tdMedicalrecord));
    }

    /**
     * 删除病历
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "病历", businessType = BusinessType.DELETE)
	@DeleteMapping("/{clinicIds}")
    public AjaxResult remove(@PathVariable String[] clinicIds)
    {
        return toAjax(tdMedicalrecordService.deleteTdMedicalrecordByClinicIds(clinicIds));
    }
}
